<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" type="text/css" href="css/login2.css">
    <link rel="stylesheet" href="js/bootstrap.min.css"/>
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <title>个人中心-收货地址页面</title>
    <script type="text/javascript">
        function deleteAddr(a_id) {
            if (confirm("是否要删除地址？")) {
                location.href = "addrDelete?a_id=" + a_id;
            }
        }

        function defaultAddr(a_id) {
            location.href = "defaultAddr?a_id=" + a_id;
        }
    </script>
</head>
<body>
<%@ include file="header.jsp" %>
<!--网站中间内容开始-->
<div id="dingdanxiangqing_body">
    <div id="dingdanxiangqing_body_big">
        <div id="big_right" style="height: 500px;overflow: scroll;">

            <div style="margin:0 20px;">
                <h3>收货地址</h3>
                <hr>
                <table class="table table-striped table-hover table-bordered">
                    <tr>
                        <th>序号</th>
                        <th>收件人</th>
                        <th>手机号</th>
                        <th>地址</th>
                        <th>操作</th>
                    </tr>
                    <c:forEach var="address" items="${addrList}" varStatus="i">
                        <tr>
                            <Td>${i.count}</Td>
                            <td>${address.recipients}</td>
                            <td>${address.phone}</td>
                            <td>${address.addrName}</td>
                            <td>
                                <button onclick="deleteAddr(${address.addressId})" class="btn btn-danger btn-sm">删除
                                </button>&nbsp;&nbsp;
                                <button class="btn btn-default btn-sm" data-toggle="modal"
                                        data-target="#myModal${address.addressId}">修改
                                </button>&nbsp;&nbsp;
                                <!-- 弹出模态框 -->

                                <div class="modal fade" tabindex="-1" role="dialog"
                                     id="myModal${address.addressId}">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal">
                                                    <span>&times;</span>
                                                </button>
                                                <h4 class="modal-title">修改地址</h4>
                                            </div>
                                            <form action="${pageContext.request.contextPath}/addrUpdate"
                                                  method="post"
                                                  class="form-horizontal">
                                                <div class="motal-body">
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">收件人</label>
                                                        <div class="col-sm-10">
                                                            <input type="hidden" name="a_id"
                                                                   value="${address.addressId}">
                                                            <input type="hidden" name="a_state"
                                                                   value="${address.defalutAddr}">
                                                            <input type="text" name="a_name" class="form-control"
                                                                   value="${address.recipients}">
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">电话</label>
                                                        <div class="col-sm-10">
                                                            <input type="text" name="a_phone" class="form-control"
                                                                   value="${address.phone}">
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label">详细地址</label>
                                                        <div class="col-sm-10">
                                                            <input type="text" name="a_detail" class="form-control"
                                                                   value="${address.addrName}">
                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="motal-footer">
                                                    <button type="submit" class="btn btn-primary">修改</button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                                <button onclick="defaultAddr(${address.addressId})" class="btn btn-primary btn-sm">
                                    设为默认
                                </button>
                                <c:if test="${address.defalutAddr==1}">
                                    <span class="badge" style="background-color:red;">默认</span>
                                </c:if>
                                <c:if test="${address.defalutAddr==0}">
                                    <span class="badge">普通</span>
                                </c:if>
                            </td>
                        </tr>
                    </c:forEach>
                </table>
            </div>
            <br>
            <div class="container" style="width:960px;">

                <form action="${pageContext.request.contextPath}/add?u_id=${user.userId}" method="post"
                      class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 form-label">收件人</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" name="a_name"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 form-label">手机号</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" name="a_phone"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="form-label">详细地址</label>
                        <textarea rows="3" class="form-control" name="a_detail"></textarea>
                    </div>
                    <div class="form-group col-md-12">
                        <input type="submit" class="btn btn-primary" value="添加地址">
                    </div>
                    <input type="hidden" value="${user.userId}" name="u_id">
                </form>
            </div>
        </div>

    </div>
</div>
<%@ include file="footer.jsp" %>
</body>
</html>